package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

/**
 * createTime：2021/8/24 9:14
 * description：SynchronizedFactory
 */


final class SyncFactory implements HasID {

    private final int id;

    private SyncFactory(ShareArg sa) {
        this.id = sa.get();
    }

    @Override
    public int getID() {
        return id;
    }

    public static synchronized SyncFactory factory(ShareArg sa) {
        return new SyncFactory(sa);
    }
}

public class SynchronizedFactory {
    public static void main(String[] args) {
        UnSafe unSafe = new UnSafe();
        IDChecker.test(() -> SyncFactory.factory(unSafe));
    }
}
